package com.hongsen.cn.Utils;

import android.text.format.Time;

public class NumberUtils {



    /**
     * 判断当前系统时间是否在指定时间的范围内
     * <p>
     * beginHour 开始小时,例如22
     * beginMin  开始小时的分钟数,例如30
     * endHour   结束小时,例如 8
     * endMin    结束小时的分钟数,例如0
     * true表示在范围内, 否则false
     */
    public static boolean isCurrentInTimeScope(int beginHour, int beginMin, int endHour, int endMin) {
        boolean result = false;
        final long aDayInMillis = 1000 * 60 * 60 * 24;
        final long currentTimeMillis = System.currentTimeMillis();
        Time now = new Time();
        now.set(currentTimeMillis);
        Time startTime = new Time();
        startTime.set(currentTimeMillis);
        startTime.hour = beginHour;
        startTime.minute = beginMin;
        Time endTime = new Time();
        endTime.set(currentTimeMillis);
        endTime.hour = endHour;
        endTime.minute = endMin;
        // 跨天的特殊情况(比如22:00-8:00)
        if (!startTime.before(endTime)) {
            startTime.set(startTime.toMillis(true) - aDayInMillis);
            result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime
            Time startTimeInThisDay = new Time();
            startTimeInThisDay.set(startTime.toMillis(true) + aDayInMillis);
            if (!now.before(startTimeInThisDay)) {
                result = true;
            }
        } else {
            //普通情况(比如 8:00 - 14:00)
            result = !now.before(startTime) && !now.after(endTime); // startTime <= now <= endTime
        }
        return result;
    }

    /**
     * 上午进  6:00-9:30       10
     * 上午出 11:25-12:00      20
     * 下午进 12:00-2:30       30
     * 下午出 16:30-6:00       40
     * @return
     */
    public static String getInfoByTime(){
        if (isCurrentInTimeScope(6,0,12,0)) {
            return "10";
        }else if (isCurrentInTimeScope(11,25,12,0)){
            return "20";
        }else if (isCurrentInTimeScope(12,0,18,0)){
            return "30";
        }else if (isCurrentInTimeScope(16,30,18,0)){
            return "40";
        }
        return "";
    }

    /**
     * 根据对应时间显示 上午进、上午出等信息
     */
    public static String getStatueByTime(){
        if (isCurrentInTimeScope(6,0,9,30)) {
            return "10";
        }else if (isCurrentInTimeScope(11,25,12,0)){
            return "20";
        }else if (isCurrentInTimeScope(12,0,2,30)){
            return "30";
        }else if (isCurrentInTimeScope(16,30,18,0)){
            return "40";
        }
        return "";
    }

}
